package com.net.xpay.common.manager.impl.admin.rbac;

import com.google.common.base.Preconditions;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.admin.rbac.RoleMenuMapper;
import com.net.xpay.common.domain.admin.rbac.RoleMenu;
import com.net.xpay.common.manager.admin.rbac.RoleMenuManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
@ReadTransactional
public class RoleMenuManagerImpl extends AbstractManager<RoleMenu> implements RoleMenuManager{

    @Autowired
    private RoleMenuMapper mapper;


    @Override
    protected BasicMapper<Long, RoleMenu> getMapper() {
        return mapper;
    }

    @Override
    public List<RoleMenu> listByRoleId(Long roleId) {
        Preconditions.checkArgument(roleId != null);
        RoleMenu condition = new RoleMenu();
        condition.setRoleId(roleId);
        return listByCondition(condition, new ArrayList<>());
    }

    @Override
    public int deleteByRoleId(Long roleId) {
        Preconditions.checkArgument(roleId != null);
        RoleMenu condition = new RoleMenu();
        condition.setRoleId(roleId);
        return deleteByCondition(condition);
    }

    @Override
    public RoleMenu getRoleMenuByMenuId(Long menuId) {
        Preconditions.checkArgument(menuId != null);
        RoleMenu condition = new RoleMenu();
        condition.setMenuId(menuId);
        return getByCondition(condition);
    }
}
